// JavaScript Document
var count = 0;
	function addCart(obj){
		var tbody = $(obj).parent().parent().parent();
		var foodName = tbody.find('tr:first td:first').text();
		var price = tbody.find('tr:first td:last').text();
		alert(foodName+" "+price);
		count++;
		document.getElementById("num").innerHTML=count;
		location="addServlet?foodName="+foodName+"&price="+parseFloat(price);
	}
	
	function delCart(id)
	{
		var res = confirm("确定删除吗?");
		if(res)
		{
			/*$('#delForm input[name=id]').val(id);
			$('#delForm').submit();*/
			//2.重写地址栏的url
			location="delServlet?id="+id;
			conut--;
			document.getElementById("num").innerHTML=count;
		}
	}
	
	function selectAll(obj){
		var alls = document.getElementsByName("all");
		for(var i=0;i<alls.length;i++)
		{
			alls[i].checked = obj.checked;
		}
		if(obj.checked)
		{
			document.getElementById("delbtn").disabled = false;
		}else{
			document.getElementById("delbtn").disabled = true;
		}
	}
	
	function delAll(){
		var flag = false;
		var res = confirm("确定要删除购物车中所有订单吗？");
		if(res){
			flag = true;
			document.getElementById("all").checked = false;
			clearCart();
			return true;
		}
		return flag;
	}
	
	/*function pay()
	{
		if(count!=0)
		{
			alert("总共付款"+total()+"元");
			clearCart();	
		}else{
			alert("您没有订任何菜品！不需要结算");
		}
	}*/
	function pay()
	{
		alert("总共付款"+total()+"元");
		clearCart();
	}
	
	
	
	function clearCart(){
		var cartTab = document.getElementById("cart");
		var len = cartTab.rows.length;
		for(var i=1;i<len;i++)
		{
			cartTab.deleteRow(1);
		}
		count = 0;
		document.getElementById("num").innerHTML=count;//更新购物车数量
		document.getElementById("delbtn").disabled = true;
		document.getElementById("empty").innerHTML="购物车空了！";
	}
	
	function total(){
		var cartTab = document.getElementById("cart");
		var cartTrs = cartTab.rows;
		var money = 0;
		for(var i=1;i<cartTrs.length;i++)
		{
			money += parseFloat(cartTrs[i].cells[2].innerHTML);
		}
		return money;
	}